<script type="text/javascript" language="javascript">

function showPreloader()
{
	var returnVal = validateMapReport()
	if(returnVal == 1)
	{
		document.getElementById('popup_div').innerHTML = '<div id="loading_txt" >Loading...</div>';
		document.frm_map_filter.submit();
	}
}

function hidePreLoader()
{
	document.getElementById('popup_div').innerHTML = '&nbsp;';
}

function mobileNoValid(id)
{
	objMobileNo = document.getElementById(id);
	if(document.getElementById(id).value.length != 10 || document.getElementById(id).value.search(/[^0-9\-()+]/g) != -1 )
	{
		//alert('Please enter valid 10 digit mobile number');
		//objMobileNo.focus();
		//objMobileNo.value="";
		return false;
	}
	else
	return true; 
	
}
var ajax1=new sack();

function changeValue()
{
	for (i=0; i<document.getElementById('selContId').length;i++)
	{
		if (document.getElementById('selContId').options[i].selected)
		{
			if(document.getElementById('txtMobileNo').value == "")
			{
				document.getElementById('txtMobileNo').value = document.getElementById('selContId').options[i].text+",";
				document.getElementById('selContId').remove(i);
			}
			else
			{
				document.getElementById('txtMobileNo').value +=document.getElementById('selContId').options[i].text+",";
				document.getElementById('selContId').remove(i);
			}
		}
	}
}


function validContForm(type)
{
	var f = 0;	
	if(document.getElementById('txtMobileNo').value == "")
	{
		alert("Enter Mobile Number"); 
		document.getElementById('txtMobileNo').focus();
		f = 1;
		return false;
	}
	else
	{
		var mobNo = document.getElementById('txtMobileNo').value.split(',');
		for(i = 0; i< mobNo.length-1; i++)
		{
			if(mobNo[i].length != 10 || mobNo[i].search(/[^0-9\-()+]/g) != -1)
			{
				alert('Please check the entered mobile number(s)');
				document.getElementById('txtMobileNo').focus();
				document.getElementById('txtMobileNo').select();
				f = 1;
				return false;
			}else f =0;
		}
	}
	if(document.getElementById('txtMessage').value == "")
	{
		alert("Enter SMS Text"); 
		document.getElementById('txtMessage').focus();
		f = 1;
		return false;
	}else f = 0;
	if(f==0)
	{
		//qry = "select * from tb_userinfo where ui_username = '"+val+"'";
		document.getElementById('cmdUpdateCont').value = "wait...";
		document.getElementById('cmdUpdateCont').disabled = true;
		ajax1.requestFile = 'ajax_server.php?sendSMS=1&numbers='+document.getElementById('txtMobileNo').value+'&mesg='+document.getElementById('txtMessage').value+'&resell='+<?php echo $_SESSION[clientID];?>;
		//alert(ajax1.requestFile);
		ajax1.onCompletion = function(){sendSmsAlert()};
		ajax1.runAJAX();
	}
	
}
function sendSmsAlert()
{
	if(ajax1.response ==1 )
	{
		alert("SMS Delivered Successfully");
		window.location.href = '?ch=sendSMS'; 
	}
	else  if(ajax1.response == 0 )
	{
		alert("SMS not Delivered Successfully");
		window.location.href = '?ch=sendSMS'; 
	}
}
function funEditUser(did,cid,act)
{
	//alert(uid)
	document.frmSubmit.txtContId.value = did;
	document.frmSubmit.txtClientId.value = cid;
	document.frmSubmit.action = act;
	document.frmSubmit.submit();
}

/*if(!mobileNoValid('txtMobileEmail'))
{
	alert('Please enter valid 10 digit mobile number');
	document.getElementById('txtMobileEmail').focus();
	f = 1;
	return false;
}*/
function showOption(e)
{
	if(e.value == "ext")
	{
		$("#existCont").show();
		$("#excelCont").hide();
	}
	else if(e.value == "excel")
	{
		$("#excelCont").show();
		$("#existCont").hide();
	}
}
function deleteUser(did,cid,act)
{
  if (confirm("Are you sure you want to delete")) {
	  document.frmSubmit.txtContId.value = did;
	document.frmSubmit.del.value = 'delete';
	document.frmSubmit.txtClientId.value = cid;
	document.frmSubmit.action = act;
	document.frmSubmit.submit();
  }
}

function sendCSVData()
{
//alert(c1);
document.frmTripData.submit();
//	window.location.href='export.php?csvData='+c1+'&frdate='+c2+'&frtime='+c3+'&totime='+c4+'&vehino='+c5;
	//document.write('export.php?csvData='+c1+'&frdate='+c2+'&frtime='+c3+'&totime='+c4+'&vehino='+c5);
}
$(function() {
	$( "#txtPolicyExp" ).datepicker({
		changeMonth: true,
		changeYear: true,
		minDate: 0,
		showOn: "button",
		buttonImage: "images/calendar.gif",
		buttonImageOnly: true,
		dateFormat : "dd-mm-yy"
	});
});
</script>
<form id="frmAddPolicy" name="frmAddPolicy" method="post" action="?ch=Device"> 
<input type="hidden" name="txtContId" id="txtContId" value="<?php echo $_POST[txtContId];?>" />
<input type="hidden" name="txtClientId" id="txtClientId" value="<?php echo $_POST[txtClientId];?>" />
<table class="gridform_final">
<tr><th colspan="2">Send SMS</th><th><a href="?ch=sendItems" style="float:right; padding-right:5%;">Sent Items</a></tr>
 <tr>
    <td align="right" width="15%" >Mobile No's</td>
    <td align="left" width="40%" >
   		<textarea name="txtMobileNo" id="txtMobileNo" class="validate[required] text-input" cols="40" rows="4" tabindex="8"><?php echo $deviceRecord[tdai_description];?></textarea> 
    </td>
    <td rowspan="5" style="background-color:#FFF; vertical-align:top;">
	<span class="detail_txt">Pick Numbers</span>&nbsp;
	<?php
		$getContInfo =  "SELECT ci_id,ci_mobileNumer FROM tb_clientinfo WHERE ci_clientId = ".$_SESSION[clientID];
		$resContInfo = mysql_query($getContInfo);
		?>
         <select name="selContId" id="selContId" tabindex="7" style="width:25%; height:200px;" size="3" onchange="changeValue()" class="validate[required]" >
         <?php 
		
		while($fetContInfo = @mysql_fetch_assoc($resContInfo)) 
		{ 
			$select ='';
		
        ?>
        <option value="<?php echo $fetContInfo[ci_id];?>" <?php echo $select ?>><?php echo $fetContInfo[ci_mobileNumer]; ?></option>
        <?php } ?>		
        </select>
    </td>
   </tr>
  <tr>
    <td align="right">Message&nbsp;<span style="color:red; font-size:10px;">(<span id="count">140</span> Chars. Left)</span></td>
    <td align="left">
	    <textarea name="txtMessage" maxlength="140" onKeyDown="return ismaxlength(this,'count')" onkeyup="return ismaxlength(this,'count')" id="txtMessage" class="validate[required] text-input" cols="40" rows="4" tabindex="8"><?php echo $deviceRecord[tdai_description];?></textarea>         
  </tr>
  <tr>
    <td colspan="3" style="text-align:center">
      <input type="button" name="cmdUpdateCont" id="cmdUpdateCont" value="Send" class="save_btn" tabindex="5" onclick="validContForm('add');" />    
      <input type="button" name="map_cancel_btn" id="map_cancel_btn" value="Cancel" class="save_btn" onclick="location.href='index.php?ch=sendSMS';" tabindex="6" /> 
    </td>
  </tr>  
</table>
</form>


<form name="frmSubmit" id="frmSubmit" method="post">
    <input type="hidden" name="txtContId" id="txtContId" />
    <input type="hidden" name="txtClientId" id="txtClientId" />
	<input type="hidden" name="del" id="del"/>

</form>